"use strict"

import Ajax from "../libs/ajax";
import Constant from "../libs/constants";
import { Message } from "iview";
export default {

    loadIpcList(params) {
        return Ajax.ajax({
            url: Constant.URL_GET_IPCLIST,
            params,
            method: 'get'
        }).then(res => res.data)
    },
    addOrUpdateIpc(editFlag, data) {
        return Ajax.ajax({
            url: editFlag ? Constant.URL_UPDATE_IPC : Constant.URL_ADD_IPC,
            data: data,
            method: 'post'
        }).then(res => res.data)
    },
    updateGuard(data) {
        return Ajax.ajax({
            url: Constant.URL_UPDATE_GUARD,
            data: data,
            method: 'post'
        }).then(res => res.data)
    },
    loadGuardData(ipc_id) {
        return Ajax.ajax({
            url: `${Constant.URL_GET_GUARD}?guard_id=${ipc_id}`,
            method: 'get'
        }).then(res => res.data)
    },
    deleteIpc(data){
        return Ajax.ajax({
            url: Constant.URL_DELETE_IPC,
            data:data,
            method: 'post'
        }).then(res => res.data)
    },
    restartIpc(data){
        return Ajax.ajax({
            url: Constant.URL_RESTART_IPC,
            data:data,
            method: 'post'
        }).then(res => res.data)
    },
    stopIpc(data){
        return Ajax.ajax({
            url: Constant.URL_STOP_IPC,
            data:data,
            method: 'post'
        }).then(res => res.data)
    },
    getPhotoLibrary(data){
        if(!data.page_size||!data.page_num){
            return new Promise((resolve, reject) => {
                resolve({ code: 2011, msg: "查询参数缺失" });
                Message.error("查询参数缺失")
            });
        }
        if(!data.ipc_id){
            return new Promise((resolve, reject) => {
                resolve({ code: 2011, msg: "请选择查询设备" });
                Message.error("请选择查询设备")
            });
        }
        return Ajax.ajax({
            url: '/api/ipc/get_photo_library',
            data:data,
            timeout: 60 * 1000,
            method: 'post'
        }).then(res => res.data)
    },
    getStudentLibraryInfo(data){
        if(!data.ipc_id||!data.student_id){
            return new Promise((resolve, reject) => {
                resolve({ code: 2011, msg: "查询参数缺失" });
                Message.error("查询参数缺失")
            });
        }
        return Ajax.ajax({
            url: '/api/ipc/get_student_library_info',
            data:data,
            timeout: 60 * 1000,
            method: 'post'
        }).then(res => res.data)
    },
    updateStudentLibraryInfo(data){
        if(!data.ipc_id||!data._id){
            return new Promise((resolve, reject) => {
                resolve({ code: 2011, msg: "参数缺失" });
                Message.error("参数缺失")
            });
        }
        return Ajax.ajax({
            url: '/api/ipc/update_student_library_info',
            data:data,
            timeout: 60 * 1000,
            method: 'post'
        }).then(res => res.data)
    },
    deleteStudentLibraryInfo(data){
        if(!data.ipc_id||!data._id){
            return new Promise((resolve, reject) => {
                resolve({ code: 2011, msg: "参数缺失" });
                Message.error("参数缺失")
            });
        }
        return Ajax.ajax({
            url: '/api/ipc/delete_student_library_info',
            data:data,
            timeout: 60 * 1000,
            method: 'post'
        }).then(res => res.data)
    },
    batchUpdateStudentLibrary(data){
        if(!data.ipc_id||!data.student_ids){
            return new Promise((resolve, reject) => {
                resolve({ code: 2011, msg: "参数缺失" });
                Message.error("参数缺失")
            });
        }
        return Ajax.ajax({
            url: '/api/ipc/batch_update_student_library',
            data:data,
            timeout: 60 * 1000,
            method: 'post'
        }).then(res => res.data)
    },
    batchDeleteStudentLibrary(data){
        if(!data.ipc_id||!data.student_ids){
            return new Promise((resolve, reject) => {
                resolve({ code: 2011, msg: "参数缺失" });
                Message.error("参数缺失")
            });
        }
        return Ajax.ajax({
            url: '/api/ipc/batch_delete_student_library',
            data:data,
            timeout: 60 * 1000,
            method: 'post'
        }).then(res => res.data)
    },
    emptyStudentLibrary(data){
        if(!data.ipc_id){
            return new Promise((resolve, reject) => {
                resolve({ code: 2011, msg: "参数缺失" });
                Message.error("参数缺失")
            });
        }
        return Ajax.ajax({
            url: '/api/ipc/empty_student_library',
            data:data,
            timeout: 60 * 1000,
            method: 'post'
        }).then(res => res.data)
    }
}